home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / CH_6.3 / XSGT / ANAL_GT.C next >
C/C++ Source or Header  |  1999-09-11  |  3KB  |  129 lines

  1. /* 
  2.  * anal_gt.c
  3.  * 
  4.  * Practical Algorithms for Image Analysis
  5.  * 
  6.  * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
  7.  */
  8.  
  9. /*
  10.  * ANAL(yze)_G(eometry and) T(opology)
  11.  *
  12.  */
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <stdarg.h>
  16. #include <math.h>
  17. #include <string.h>
  18. #include "vora.h"
  19.  
  20.  
  21. /* globals */
  22. extern int CHECK_EDGE;
  23.  
  24. /*
  25.  * extract, from struct vSite array, vPoly areas and domain areas,
  26.  * both normalized to their respective mean values, for later processing
  27.  */
  28. int
  29. a_vs_vPa (struct Pix *dpa, int ns, struct vSite *vsa, double *a_bar, double *va_bar)
  30. {
  31.   int is, nma;
  32.   double ma, mva;
  33.   struct vSite *vS;
  34.  
  35.   nma = 0;
  36.   ma = 0.0;
  37.   mva = 0.0;
  38.   for (is = 0; is < ns; is++) {
  39.     if (((vS = (vsa + is))->eFlag == UnSet) &&
  40.         (vS->aoiFlag == UnSet)) {
  41.       mva += (dpa + is)->x = (float) (vsa + is)->v_area;
  42.       ma += (dpa + is)->y = (float) (vsa + is)->area;
  43.       nma++;
  44.     }
  45.   }
  46.   *va_bar = (mva /= (double) nma);
  47.   *a_bar = (ma /= (double) nma);
  48.  
  49.   for (is = 0; is < ns; is++) {
  50.     if (((vS = (vsa + is))->eFlag == UnSet) &&
  51.         (vS->aoiFlag == UnSet)) {
  52.       (dpa + is)->x /= (float) mva;
  53.       (dpa + is)->y /= (float) ma;
  54.     }
  55.     else {
  56.       (dpa + is)->x = (float) -1.0;
  57.       (dpa + is)->y = (float) -1.0;
  58.     }
  59.   }
  60.   return (nma);
  61. }
  62.  
  63.  
  64. /*
  65.  * joint probability distribution, p(n, A)
  66.  * construct joint probability distribution, p(n, A), of site 
  67.  * coordination, n, and bubble domain area, A
  68.  */
  69. double
  70. p_of_nA (int *ndn, unsigned int *a_n[], int ns, struct vSite *vsa)
  71. {
  72.   int is, cnn;
  73.   int nma;
  74.   double ma;
  75.   struct vSite *vS;
  76.  
  77.   nma = 0;
  78.   ma = 0.0;
  79.   for (is = 0; is < ns; is++) {
  80.     if (((vS = (vsa + is))->eFlag == UnSet) &&
  81.         (vS->aoiFlag == UnSet)) {
  82.       cnn = (vsa + is)->nnn;
  83.       *(a_n[cnn] + ndn[cnn]) = (vsa + is)->area;
  84.       ndn[cnn]++;
  85.  
  86.       ma += (vsa + is)->area;
  87.       nma++;
  88.     }
  89.   }
  90.   ma /= (double) nma;
  91.   return (ma);
  92. }
  93.  
  94.  
  95.  
  96.  
  97. /*
  98.  * evaluate distance of closest approach between NN pairs of domains
  99.  *
  100.  * eFlag and aoiFlag are of type Boolean
  101.  */
  102. int
  103. eval_sij (float *bs[], int ns, struct vSite *vsa)
  104. {
  105.   int ibs;
  106.   int is, inn;
  107.   double r_i, r_j;
  108.   struct vSite *vS;
  109.  
  110.   printf ("\n");
  111.   ibs = 0;
  112.   for (is = 0; is < ns; is++) {
  113.     if (((vS = (vsa + is))->eFlag == UnSet) &&
  114.         (vS->aoiFlag == UnSet)) {
  115.       r_i = sqrt ((double) (vS->area) / PI);
  116.       for (inn = 0; inn < vS->nnn; inn++) {
  117.         r_j = sqrt ((double) (vsa + (vS->nnsi[inn]))->area / PI);
  118.  
  119.         *(bs[is] + inn) = vS->nnd[inn] - (float) (r_i + r_j);
  120.         ibs++;
  121.       }
  122.     }
  123.     else {
  124.       printf ("WARNING: Site %d out of bounds\n", vS->sitenbr);
  125.     }
  126.   }
  127.   return (ibs);
  128. }
  129.